package com.cammus.qatar.utils;

import android.app.Activity;
import android.content.Intent;

import com.cammus.qatar.R;


/**
 * @Created by toDoMan on 2017/10/13.
 * @Company: 深圳市卡丁汇公司
 * @Description: Activity跳转动画类
 */
public class AnimUtils {
    public static final int SLIDE_TO_LEFT = 1;
    public static final int SLIDE_TO_RIGHT = 2;
    public static final int SLIDE_UP = 3;
    public static final int SLIDE_DOWN = 4;
    public static final int SCALE_IN = 5;
    public static final int SCALE_OUT = 6;
    public static final int SCALE_ONLY_IN = 7;
    public static final int SCALE_ONLY_OUT = 8;
    public static final int SLIDE_UP_85 = 9;
    public static final int ACTIVITY_POP = 10;
    public static final int ACTIVITY_BOTTOM=11;

    public static void startActivity(Activity activity, int mode) {
        if (activity == null) return;
        try {
            switch (mode) {
                case SLIDE_TO_LEFT:
                    activity.overridePendingTransition(R.anim.default_activity_open_enter, R.anim.slide_to_left);
                    break;
                case SLIDE_TO_RIGHT:
                    activity.overridePendingTransition(R.anim.slide_to_right, R.anim.default_activity_close_exit);
                    break;
                case SLIDE_UP:
                    activity.overridePendingTransition(R.anim.slide_up, 0);
                    break;
                case SLIDE_UP_85:
                    activity.overridePendingTransition(R.anim.slide_up_85, 0);
                    break;
                case SLIDE_DOWN:
                    activity.overridePendingTransition(0, R.anim.slide_down);
                    break;
                case SCALE_IN:
                    activity.overridePendingTransition(R.anim.default_dialog_open_enter, R.anim.default_dialog_close_exit);
                    break;
                case SCALE_OUT:
                    activity.overridePendingTransition(R.anim.default_dialog_open_enter, R.anim.default_dialog_close_exit);
                    break;
                case SCALE_ONLY_IN:
                    activity.overridePendingTransition(R.anim.default_dialog_open_enter, 0);
                    break;
                case SCALE_ONLY_OUT:
                    activity.overridePendingTransition(0, R.anim.default_dialog_close_exit);
                    break;
                case ACTIVITY_POP:
                    activity.overridePendingTransition(0, R.anim.activity_pop_window);
                    break;
                case ACTIVITY_BOTTOM:
                    activity.overridePendingTransition(R.anim.activity_bottom_in,R.anim.activity_bottom_silent);
                    break;
                default:
                    break;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void startActivity(Activity activity, Class clasz, int mode) {
        if (activity == null || clasz == null) {
            return;
        }
        try {
            if (clasz != null) {
                Intent intent = new Intent(activity, clasz);
                activity.startActivity(intent);
            }
            switch (mode) {
                case SLIDE_TO_LEFT:
                    activity.overridePendingTransition(R.anim.default_activity_open_enter, R.anim.slide_to_left);
                    break;
                case SLIDE_TO_RIGHT:
                    activity.overridePendingTransition(R.anim.slide_to_right, R.anim.default_activity_close_exit);
                    break;
                case SLIDE_UP:
                    activity.overridePendingTransition(R.anim.slide_up, 0);
                    break;
                case SLIDE_UP_85:
                    activity.overridePendingTransition(R.anim.slide_up_85, 0);
                    break;
                case SLIDE_DOWN:
                    activity.overridePendingTransition(0, R.anim.slide_down);
                    break;
                case SCALE_IN:
                    activity.overridePendingTransition(R.anim.default_dialog_open_enter, R.anim.default_dialog_close_exit);
                    break;
                case SCALE_OUT:
                    activity.overridePendingTransition(R.anim.default_dialog_open_enter, R.anim.default_dialog_close_exit);
                    break;
                case SCALE_ONLY_IN:
                    activity.overridePendingTransition(R.anim.default_dialog_open_enter, 0);
                    break;
                case SCALE_ONLY_OUT:
                    activity.overridePendingTransition(0, R.anim.default_dialog_close_exit);
                    break;
                default:
                    break;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void startActivity(Activity activity, Intent intent, int mode) {
        if (activity == null || intent == null) {
            return;
        }
        try {
            if (intent != null) {
                activity.startActivity(intent);
            }
            switch (mode) {
                case SLIDE_TO_LEFT:
                    activity.overridePendingTransition(R.anim.default_activity_open_enter, R.anim.slide_to_left);
                    break;
                case SLIDE_TO_RIGHT:
                    activity.overridePendingTransition(R.anim.slide_to_right, R.anim.default_activity_close_exit);
                    break;
                case SLIDE_UP:
                    activity.overridePendingTransition(R.anim.slide_up, 0);
                    break;
                case SLIDE_UP_85:
                    activity.overridePendingTransition(R.anim.slide_up_85, 0);
                    break;
                case SLIDE_DOWN:
                    activity.overridePendingTransition(0, R.anim.slide_down);
                    break;
                case SCALE_IN:
                    activity.overridePendingTransition(R.anim.default_dialog_open_enter, R.anim.default_dialog_close_exit);
                    break;
                case SCALE_OUT:
                    activity.overridePendingTransition(R.anim.default_dialog_open_enter, R.anim.default_dialog_close_exit);
                    break;
                case SCALE_ONLY_IN:
                    activity.overridePendingTransition(R.anim.default_dialog_open_enter, 0);
                    break;
                case SCALE_ONLY_OUT:
                    activity.overridePendingTransition(0, R.anim.default_dialog_close_exit);
                    break;
                default:
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void startActivityForResult(Activity activity, int requestCode, Intent intent, int mode) {
        if (activity == null || intent == null) {
            return;
        }
        try {
            if (intent != null) {
                activity.startActivityForResult(intent, requestCode);
            }
            switch (mode) {
                case SLIDE_TO_LEFT:
                    activity.overridePendingTransition(R.anim.default_activity_open_enter, R.anim.slide_to_left);
                    break;
                case SLIDE_TO_RIGHT:
                    activity.overridePendingTransition(R.anim.slide_to_right, R.anim.default_activity_close_exit);
                    break;
                case SLIDE_UP:
                    activity.overridePendingTransition(R.anim.slide_up, 0);
                    break;
                case SLIDE_UP_85:
                    activity.overridePendingTransition(R.anim.slide_up_85, 0);
                    break;
                case SLIDE_DOWN:
                    activity.overridePendingTransition(0, R.anim.slide_down);
                    break;
                case SCALE_IN:
                    activity.overridePendingTransition(R.anim.default_dialog_open_enter, R.anim.default_dialog_close_exit);
                    break;
                case SCALE_OUT:
                    activity.overridePendingTransition(R.anim.default_dialog_open_enter, R.anim.default_dialog_close_exit);
                    break;
                case SCALE_ONLY_IN:
                    activity.overridePendingTransition(R.anim.default_dialog_open_enter, 0);
                    break;
                case SCALE_ONLY_OUT:
                    activity.overridePendingTransition(0, R.anim.default_dialog_close_exit);
                    break;
                default:
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void exitActivity(Activity activity) {
        activity.finish();
        activity.overridePendingTransition(R.anim.activity_enter, R.anim.activity_exit);
    }
}
